package com.c2soft.nepalcmx.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.log4j.Log4j2;

import org.apache.log4j.Category;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.codehaus.plexus.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.c2soft.nepalcmx.command.AccountDetailCommand;
import com.c2soft.nepalcmx.command.AccountUserCommand;
import com.c2soft.nepalcmx.command.BrokerFormCommand;
import com.c2soft.nepalcmx.services.BrokerListServices;
import com.c2soft.nepalcmx.services.BrokerFormService;
import com.c2soft.nepalcmx.util.JsonUtil;

@Log4j2
@Controller
@RequestMapping("/broker")
public class BrokerFormController {

	@Autowired
	private BrokerFormService brokerFormService;

	@RequestMapping(value = "/registration", method=RequestMethod.POST, headers = "Accept=application/json")
	@ResponseBody
	public String registration( @RequestBody String json) {
		BrokerFormCommand registration= (BrokerFormCommand) JsonUtil.fromJson(json,BrokerFormCommand.class);
		brokerFormService.registrationService(registration);
		return "{\"msg\":\"Broker is Registered successfully.\"}";
	}
	
	
	
@RequestMapping(value = "/brokerDetail",method=RequestMethod.GET, headers = "Accept=application/json")
	
	public @ResponseBody List<BrokerFormCommand> getBrokerForm() {
		List<BrokerFormCommand> brokerdetail=brokerFormService.getBrokerForm();
		return brokerdetail;
	}

	
@RequestMapping(value = "/getList",method=RequestMethod.GET, headers = "Accept=application/json")	
	public @ResponseBody List<BrokerFormCommand> getAccountDetail() {
		List<BrokerFormCommand> users=brokerFormService.getBrokerForm();
		return users;
	}

@RequestMapping(value = "/selectUser",method={RequestMethod.POST,RequestMethod.GET}, headers = "Accept=application/json")
public @ResponseBody List<BrokerFormCommand> updateUserData(HttpServletRequest req,@RequestBody String brokerId) {
	List<BrokerFormCommand> brokers=brokerFormService.getBrokerDetail(brokerId);
	return brokers;
}


@RequestMapping(value = "/updateUser", method=RequestMethod.POST, headers = "Accept=application/json")
@ResponseBody
public String updateAccount( @RequestBody String json) {
		BrokerFormCommand user= (BrokerFormCommand) JsonUtil.fromJson(json,BrokerFormCommand.class);
    brokerFormService.updateBrokerService(user);
	return "{\"msg\":\"Password updated successfully.\"}";
}

@RequestMapping(value = "/getBrokerDetail", method=RequestMethod.GET,headers = "Accept=application/json")

public @ResponseBody List<AccountUserCommand> getBrokerDetail( HttpServletRequest req) {
	
	String brokerId=(String) req.getSession().getAttribute("UsrId");
	List<AccountUserCommand> accUser=brokerFormService.getBrokersDetail(brokerId);
	return accUser;
}

@RequestMapping(value = "/getBrokerDetail1", method=RequestMethod.GET,headers = "Accept=application/json")
public @ResponseBody List<AccountUserCommand> getBrokerDetail1( @RequestParam("brokerId") String brokerId) {
	List<AccountUserCommand> accUser=brokerFormService.getBrokersDetail(brokerId);
	return accUser;
}

@RequestMapping(value = "/getExchangeDetail", method=RequestMethod.GET,headers = "Accept=application/json")

public @ResponseBody List<AccountUserCommand> getExchangeDetail( HttpServletRequest req) {
	List<AccountUserCommand> accUser=brokerFormService.getExchangeDetail();
	return accUser;
}
}
